/*
 * $Id: sshc.h 7557b5d4d82b 2012/12/02 09:07:16 pgurumur $
 *
 * Copyright (c) 2006, 2007, 2008 Prabhu Gurumurthy <pgurumur@gmail.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef __SSHC_H_
#define __SSHC_H_

#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>

#include <netinet/in.h>
#include <arpa/inet.h>

#include <assert.h>
#include <err.h>
#include <errno.h>
#include <event.h>
#include <ctype.h>
#include <fcntl.h>
#include <netdb.h>
#include <poll.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>

#include <libssh2.h>
#include <libssh2_publickey.h>
#include <libssh2_sftp.h>

#define CMDLINE_BUF 8192
#define DEF_SSH_PORT 22
#define DEF_SERVICE_NAME "ssh"
#define DEF_BANNER "LibSSH_2.0"
#define DEF_MESG "Normal shutdown"
#define DEF_TERM "xterm"
#define DEF_TIMEOUT 1000
#define MAXLINE 8192
#define MINBUF 2048
#define MAX_FINGERPRINT 16
#define MINPORT  1
#define MAXPORT  65535 
#define STDIN 0

struct _sshc {
   LIBSSH2_SESSION *session;
   LIBSSH2_CHANNEL *channel; 

   const char *user;
   const char *host;
   const char *version;
   char prikey[MAXLINE];
   char pubkey[MAXLINE];
   const char *keypass;
   const char *tempfile;
   
   FILE *logstream;
   FILE *input;

   int af;
   int sock;
   int port;
};

__BEGIN_DECLS
/* sshc.c */
int main(int, char *[]);
void usage(void);

/* signal.c */
void handle_signal(int);

/* error.c */
void error(int, const char *, ...);
void warning(int, const char *, ...);
char *ssh_geterror(void);

/* client.c */
void ssh_init(const char *, const u_int16_t, int);
void ssh_session(void);
int ssh_kiauth(const char *);
int ssh_pkauth(const char *);
int ssh_passauth(const char *, const char *);
void ssh_userauth(const char *, const char *);
void ssh_info(void);

/* shutdown.c */
void ssh_shutdown(void);
void cleanup(void);

/* log.c */
void log_init(void);
void logit(int, const char *, ...);

/* tty.c */
char *read_pass(const char *);
void ssh_getty(const char *, const int);

/* io.c */
int wait_fd(int, int);
int ssh_read(int, int, int);
int ssh_write(int, int);
void blocking(int, int);
void ssh_send_eof(void);

__END_DECLS

extern char *__progname;
char errmsg[MAXLINE];
struct _sshc *sshc;
int verbose;
int debug;
int got_channel;
int got_password;

#endif
